package com.gss.armory.master;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.springframework.security.core.GrantedAuthority;

import com.gss.security.domain.UserRoleMappingDTO;

@Entity
@Table(name="LC_ROLE_DETAILS")
public class RoleDetailsAuthDTO implements GrantedAuthority, Serializable{

	private String roleDesc;
	private String roleId;
	private Integer appId;

	

	@Id
	@Column(name="RD_ROLE_ID",length=20)
	public String getAuthority() {
		// TODO Auto-generated method stub
		return roleId;
	}
	
	@Column(name="RD_APP_ID")
	public Integer getAppId() {
		return appId;
	}
	
	@Column(name="RD_ROLE_NAME",length=100)
	public String getRoleDesc() {
		return roleDesc;
	}

	public void setRoleDesc(String roleDesc) {
		this.roleDesc = roleDesc;
	}
	
	

	public void setAppId(Integer appId) {
		this.appId = appId;
	}

	@Transient
	public String getRoleId() {
		return roleId;
	}

	public void setRoleId(String roleId) {
		this.roleId = roleId;
	}

	public void setAuthority(String roleId){
		this.setRoleId(roleId);
	}

	@Override
	public boolean equals(Object obj) {
		
		if(obj!=null)
		{
			if(obj instanceof RoleDetailsAuthDTO)
			{
				RoleDetailsAuthDTO roleDetailsDTO = (RoleDetailsAuthDTO)obj;
				if(roleDetailsDTO.getRoleId()!=null&&this.roleId!=null)
				{
					return roleDetailsDTO.getRoleId().equalsIgnoreCase(roleId);
				}
				else if(roleDetailsDTO.getRoleId()==null&&this.roleId==null)
					return true;
				else
					return false;
					
			}
			return false;
		}
		return false;
	}
	
	@Override
	public int hashCode() {
		// TODO Auto-generated method stub
		
		return this.roleId.hashCode();
	}

	@Override
	public String toString() {
		return "RoleDetailsAuthDTO [roleDesc=" + roleDesc + ", roleId=" + roleId
				+ "]";
	}
}
